<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>

<SCRIPT TYPE="text/javascript">
<!--
function detail(workflow) {
	if (window.XMLHttpRequest) // IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	else // IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	
	var html = "<table class='files' id='files'>"
		+ "<tr><th colspan='3'>" +workflow +"</th><tr>"
		+ "<tr>"
		+ "<th align='left'>Input</th>"
		+ "<th align='center'><fmt:message key="table.size"/></th>"
		+ "<th align='center'><fmt:message key="table.modified"/></th>"
		+ "</tr>";

	var name;
	xmlhttp.open("GET","upload?workflow=" +workflow,false);
	xmlhttp.send();
	xmlDoc=xmlhttp.responseXML; 
	var x=xmlDoc.getElementsByTagName("input");
	for (i=0;i<x.length;i++) { 
		name=x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue;
		html = html 
		+ "<tr><td>"
		+ "<a href='upload?file=" +workflow +"/input/" +name +"''>" +name
		+ "</td><td align='right'>"
		+ x[i].getElementsByTagName("size")[0].childNodes[0].nodeValue
		+ "</td><td align='right'>"
		+ x[i].getElementsByTagName("modified")[0].childNodes[0].nodeValue
		+ "</td></tr>";
	}
	
	html = html
		+ "<th align='left'>Output</th>"
		+ "<th align='center'><fmt:message key="table.size"/></th>"
		+ "<th align='center'><fmt:message key="table.modified"/></th>"
		+ "</tr>";
	x=xmlDoc.getElementsByTagName("output");
	for (i=0;i<x.length;i++) { 
		name=x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue;
		html = html 
		+ "<tr><td>"
		+ "<a href='upload?file=" +workflow +"/output/" +name +"''>" +name
		+ "</td><td align='right'>"
		+ x[i].getElementsByTagName("size")[0].childNodes[0].nodeValue
		+ "</td><td align='right'>"
		+ x[i].getElementsByTagName("modified")[0].childNodes[0].nodeValue
		+ "</td></tr>";
	}
	
	html = html + "</table>";
	document.getElementById('detaildiv').innerHTML = html;
}

function refresh() {
	document.getElementById('detaildiv').innerHTML = "&nbsp";
	
	if (window.XMLHttpRequest) // IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	else // IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	
	var html = "<table class='files' id='files'>"
		+ "<tr><th><fmt:message key="table.header"/></th><tr>";

	xmlhttp.open("GET","upload?get=previous",false);
	xmlhttp.send();
	xmlDoc=xmlhttp.responseXML; 
	var x=xmlDoc.getElementsByTagName("workflow");
	var name;
	for (i=0;i<x.length;i++) { 
		name=x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue;
		html = html 
		+ "<tr><td>"
		+ "<a href=\"javascript:detail('" +name +"')\">" +name
		+ "</td></tr>";
	}
	
	if (window.XMLHttpRequest) // IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	else // IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp.open("GET","upload?get=current",false);
	xmlhttp.send();
	xmlDoc=xmlhttp.responseXML; 
	var x=xmlDoc.getElementsByTagName("workflow");
	var name;
	for (i=0;i<x.length;i++) { 
		name=x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue;
		html = html + "<tr><td>" + name + "</td></tr>";
	}
	
	html = html + "</table>";
	document.getElementById('tablediv').innerHTML = html;
}

function deleteworkflow(name) {
	var del = confirm("Are you sure you want to delete '" +name +"' ?");
	if (del) {
		if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		}
		else {// code for IE6, IE5
	  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.open("DELETE","upload?workflow=" +name,false);
		xmlhttp.send();
		refresh();
	}
}
//-->
</SCRIPT>

<button onclick="window.location.href='workflow.html'"><fmt:message key="button.new"/></button>
<div>
<div id="tablediv" style="float: left">&nbsp</div>
<div id="detaildiv" style="float: left">&nbsp</div>
</div>

<script type="text/javascript">
<!--
refresh();
//-->
</script>